﻿<!DOCTYPE html>
<html>
<head>
  <!-- 页面meta -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>传智健康</title>
  <meta name="description" content="传智健康">
  <meta name="keywords" content="传智健康">
  <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../plugins/elementui/index.css">
  <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="../css/style.css">
  <!-- 引入组件库 -->
  <script type="text/javascript" src="../js/jquery.min.js"></script>
  <script src="../js/vue.js"></script>
  <script src="../plugins/elementui/index.js"></script>
  <script src="../js/axios-0.18.0.js"></script>
  <style>
    .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409EFF;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
    .datatable {
      position: relative;
      box-sizing: border-box;
      -webkit-box-flex: 1;
      width: 100%;
      max-width: 100%;
      font-size: 14px;
      color: rgb(96, 98, 102);
      overflow: hidden;
      flex: 1 1 0%;
    }
    .datatable td, .datatable th {
      padding: 12px 0;
      min-width: 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      text-overflow: ellipsis;
      vertical-align: middle;
      position: relative;
      text-align: left;
    }
  </style>
  <script src="../plugins/healthmobile.js"></script>
</head>
<body class="hold-transition">
<div id="app">
  <div class="content-header">
    <h1>会员管理<small>体检上传</small></h1>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>会员管理</el-breadcrumb-item>
      <el-breadcrumb-item>体检上传</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <div class="app-container">
    <div class="box">
      <div class="filter-container">
        <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
        <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
      </div>
      <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
        <el-table-column type="index" align="center" label="序号"></el-table-column>
        <el-table-column prop="orderDate" label="体检时间" align="center"></el-table-column>
        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
        <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
        <el-table-column prop="setmeal_name" label="检查套餐" align="center"></el-table-column>
        <el-table-column prop="orderStatus" label="报告状态" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="info" size="mini" @click="handleCreate(scope.row)" plain>上传报告</el-button>
            <el-button  type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
      </div>
      <!-- 添加标签弹层-->
      <div class="add-form">
        <el-dialog title="上传报告" :visible.sync="dialogFormVisible">
          <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="姓名" prop="name">
                  <el-input v-model="formData.name" disabled/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="档案号" prop="fileNumber">
                  <el-input v-model="formData.fileNumber" disabled/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="体检时间" prop="orderDate">
                  <el-input v-model="formData.orderDate" disabled/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="18">
                <el-form-item label="档案文件" prop="file">
                  <el-upload
                             class="upload-demo"
                             action="/member/upload.do"
                             :before-remove="beforeRemove"
                             :before-upload="beforeUpload"
                             :limit="1"
                             ref="upload"
                             :on-exceed="handleExceed"
                             :on-success="handSuccess">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">文件大小不要超过2MB</div>
                  </el-upload>
                </el-form-item>
              </el-col>
            </el-row>

          </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取消</el-button>
              <el-button type="primary" @click="handleAdd(formData.order_id)">确定</el-button>
            </div>
        </el-dialog>
      </div>
    </div>
  </div>
</div>
</body>
<script src="../plugins/healthmobile.js"></script>
<script>

    var Main = {
        data() {
            return {
                pagination: {//分页相关属性
                    currentPage: 1,  //当前页
                    pageSize:10,  //一页显示的数量
                    total:100,  //总数
                    queryString:null //查询条件
                },
                dataList: [],//列表数据
                formData: {
                    sex : '不限'
                },//表单数据
                tableData:[],//添加表单窗口中检查组列表数据
                dialogFormVisible: false,//控制增加窗口显示/隐藏
                dataAddForm: {
                    file: ''
                },
                rules: {
                    //文件验证
                    file: [
                        {required: true, message: '请上传文件', trigger: 'blur' },
                          ]
                },
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //日期转换
            dateFormat:function(time) {
                var date=new Date(time);
                var year=date.getFullYear();
                /* 在日期格式中，月份是从0开始的，因此要加0
                 * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
                 * */
                var month= date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1;
                var day=date.getDate()<10 ? "0"+date.getDate() : date.getDate();
                // 拼接
                return year+"-"+month+"-"+day;
            },
            //个数限制提示
            handleExceed() {
                this.$message.warning(`只能选择一个文件，请删除刚才的文件`);
            },
            //上传成功时
            handSuccess(file){
                this.resetRules('dataAddForm');
                //手动取消为空验证
                this.rules.file[0].required = false;
            },
            //上传文件之前执行
            beforeUpload(file) {
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isLt2M) {
                    this.$message.error('上传套餐图片大小不能超过 2MB');
                }

            },
            //删除文件提示
            beforeRemove(file) {
                return this.$confirm(`确定移除 ${ file.name }？`);
            },


            //弹出添加页面
            handleCreate(row){
                this.resetRules('dataAddForm');
                this.rules.file[0].required = true;
                //重置表单验证
                this.resetForm();
                //打开窗口
                this.dialogFormVisible = true;
                this.formData.name = row.name;
                this.formData.fileNumber = row.fileNumber;
                this.formData.orderDate = row.orderDate;
                this.formData.order_id = row.order_id;
                this.formData.orderStatus = row.orderStatus;
            },
            //上传报告
            handleAdd(){
                this.$refs['dataAddForm'].validate((valid) => {
                    if(valid){
                        axios.post('/member/uploadCheck.do?id='+this.formData.order_id).then((res) => {
                            if(this.formData.orderStatus === '已报告'){
                                this.$message.error('请勿重复报告');
                                return;
                            }
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                this.dialogFormVisible = false;
                                this.findPage();
                            }else {
                                this.$message.error(res.data.message);
                            }
                        })
                    }
                });

            },
            //分页查询
            findPage() {
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString:this.pagination.queryString
                };
                //发送ajax请求，进行分页查询
                axios.post("/member/findCheckPage.do",param).then((res) => {
                    this.pagination.total = res.data.total;
                    /*循环更改日期格式*/
                    for (i in res.data.rows) {
                        res.data.rows[i].orderDate=this.dateFormat(res.data.rows[i].orderDate);
                    }
                    this.dataList = res.data.rows;
                });
            },
            //删除体检报告
            handleDelete(row){
                if(row.orderStatus === '已报告'){
                    this.$message.error('无法删除已经报告的体检信息');
                    return;
                }
                //弹出确认框
                this.$confirm('你确定要删除当前数据吗？','提示',{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求，将id提交到Controller
                    axios.get("/member/deleteCheck.do?id=" + row.order_id).then((res) => {
                        if(res.data.flag){
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message("已取消");
                });
            },
            // 重置表单
            resetForm() {
                if (this.$refs.upload!==undefined) {
                    this.$refs.upload.clearFiles()
                }
            },
            //重置验证
            resetRules(formName) {
                if (this.$refs[formName]!==undefined) {
                    this.$refs[formName].resetFields()
                }
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;//指定最新的页码
                this.findPage();
            }
        }
    }
    var Ctor = Vue.extend(Main)
    new Ctor().$mount('#app')

</script>
</html>
